package 异常的学习;

import java.util.Scanner;
public class PTA1{
    public static void main(String [ ] args){
        Scanner in=new Scanner(System.in);
        double side1,side2,side3;
        side1=in.nextDouble();
        side2=in.nextDouble();
        side3=in.nextDouble();
        Triangle t;
        //下面的代码创建Triangle对象，使用try catch处理异常
        try{
            t=new Triangle(side1,side2,side3);
            System.out.println("三角形创建成功");
        }catch(IllegalTriangleException e){
            System.out.println(e.getMessage());
        }
    }
}
    class Triangle{
        private double side1;
        private double side2;
        private double side3;
        public Triangle(double side1,double side2,double side3)
                throws IllegalTriangleException{//初始化，如果出现两条边之和小于等于第三边，则抛出 IllegalTriangleException异常对象
            if(side1+side2<=side3&&side3+side2<=side1&&side1+side3<=side2){
                throw new IllegalTriangleException();
            }
        }
    }

    class  IllegalTriangleException extends Exception{//下面的代码定义异常类
        public IllegalTriangleException(){
            super("边长不符合要求");
        }
    }
